//
//  AboutViewController.m
//  Gabber
//
//  Created by 陆惠国 on 11-9-16.
//  Copyright 2011年 恒生聚源. All rights reserved.
//

#import "AboutViewController.h"
#import "XMPPClient.h"

@implementation AboutViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"关于";
        self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"关于" image:[UIImage imageNamed:@"about.png"] tag:3] autorelease];  
        self.tableViewStyle = UITableViewStyleGrouped;
        self.variableHeightRows = YES;
        
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    if (TTIsPad()) {
        return YES;
        
    } else {
        return interfaceOrientation == UIInterfaceOrientationPortrait;
    }
}

#pragma mark - TTModelViewController
- (void)createModel {
    if (TTIsPad()){
        self.dataSource = [TTSectionedDataSource dataSourceWithObjects:
                           @"",
                           [TTTableCaptionItem itemWithText:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"] caption:@"产品名称"],
                           [TTTableCaptionItem itemWithText: [NSString stringWithFormat:@"%@ (%@)",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]] caption:@"产品版本"],
                           [TTTableCaptionItem itemWithText:@"© 2011 Gildata Inc." caption:@"版权所有"],
                           nil];        
    }else{
        self.dataSource = [TTSectionedDataSource dataSourceWithObjects:
                           @"",
                           [TTTableCaptionItem itemWithText:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"] caption:@"产品名称"],
                           [TTTableCaptionItem itemWithText: [NSString stringWithFormat:@"%@ (%@)",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]] caption:@"产品版本"],
                           [TTTableCaptionItem itemWithText:@"© 2011 Gildata Inc." caption:@"版权所有"],
                           @"",
                           [TTTableButton itemWithText:@"重新登录" delegate:self selector:@selector(logoutAction)],
                           nil];        
    }
    
    
    
}

#pragma mark - Actions

- (void)logoutAction
{
    [[XMPPClient sharedInstance] disconnect];
    TTOpenURL(@"gabber://login");
}

@end
